﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NullObjectStudy
{
    public class Student
    {
        public virtual int Age { get; set; }

        public virtual bool GetMarryStatus()
        {
            if (Age > 28)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public virtual void DoSomething()
        {
            Console.WriteLine("sssssssssssss");
        }

        private DateTime? timeCreated;
        /// <summary>
        /// 创建时间
        /// </summary>
        /// <returns></returns>
        public virtual DateTime GetCreateTime()
        {
            if (timeCreated.HasValue==false)
            {
                timeCreated = DateTime.Now;
            }
            return timeCreated.Value;
        }
            

        private class NullStudent : Student
        {
            public override int Age
            {
                get
                {
                    return 0;
                }
            }

            public override bool GetMarryStatus()
            {
                return false;
            }

            public override void DoSomething()
            {
                //do nothing;
            }
        }

        public static Student nullStudent = null;
        public static Student Null
        {
            get
            {
                if (nullStudent == null)
                {
                    nullStudent = new NullStudent();
                }
                return nullStudent;
            }
        }
    }
}
